<?php
namespace app\index\controller;

class Index
{
    public function index()
    {
        return '地址错误';
    }


    //投票列表数据
    public function getVoteList()
    {
    	$request = input('param.');
		$request['page'] = empty($request['page']) ? 1 : $request['page'];
    	$data = db("vote_activityconfig")->where('status',1)->order('id desc')->paginate($request['size'],false,['page' => $request['page']])->->toArray();
    	return json_encode($data);

    }

    //新增投票
    public function voteInsert()
    {
    	$request = input('param.');
    	$result = db("vote_activityconfig")->insert($request);
    	if ($result) {
    		return json_encode(['info' => '新增成功','code' => 1]);
    	} else {
    		return json_encode(['info' => '新增失败','code' => 0]);
    	}

    }


    //投票详细数据
    public function voteInfo()
    {
    	$id = input('param.id');
    	if (!$id) {
    		return json_encode(['info' => '参数错误','code' => 0])；
    	}
    	$result = db("vote_activityconfig")->where('id',$id)->find();
    	return json_encode($result);
    }



    //更新投票
    public function updateVote()
    {
    	$request = input('param.');
    	if (!$request['id']) {
    		return json_encode(['info' => '参数错误','code' => 0])；
    	}
    	$result = db("vote_activityconfig")->where('id',$request['id'])->update();
    	return json_encode(['info' => '更新成功','code' => 1]);
    }


}
